package com.bianmaba.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public final class NumericUtils {
    private NumericUtils() {
    }

    public static boolean isInteger(String val) {
        if (val == null) {
            return false;
        }
        Pattern pattern = Pattern.compile("[\\s]*[+-]{0,1}[0-9]+[\\s]*");
        Matcher isNum = pattern.matcher(val);
        return isNum.matches();
    }

    public static boolean isDouble(String val) {
        if (val == null) {
            return false;
        }
        Pattern pattern = Pattern.compile("[\\s]*[+-]?[\\d]+(\\.[\\d]*)?[\\s]*");
        Matcher isNum = pattern.matcher(val);
        return isNum.matches();
    }

    public static int parseInt(String val) {
        return Integer.parseInt(val.trim());
    }

    public static double parseDouble(String val) {
        return Double.parseDouble(val.trim());
    }
}
